<!--
Date: 2025-08-13
Copyright (c) 2025 Industrial Software Feature Database
-->
<template>
    <el-dialog v-model="props.resultVisible" title="计算结果" @close="handleVisible()" width="850">
      <el-form size="small">
        <el-form-item label="算法">
          <el-select v-model="queryParams.algorithm" @change="changeAlgorithm">
            <el-option v-for="item in algorithms" :label="item.name" :value="item.value" :key="item.label"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-card class="basic" v-if="props.rowData">
        <div>基础信息</div>
        <div class="split" ></div>
        <div class="row">
          <div class="item" v-for="item in basicData" :key="item.label">
            <span>{{ item.label }}：</span> <span>{{ props?.rowData[item.value] }}</span>
          </div>
        </div>
      </el-card>
      <el-card class="result">
        <el-table :data="tableData">
          <el-table-column :label="item.label" v-for="item in columns" :key="item.label" :prop="item.prop"/>
        </el-table>
        <div class="pagenation">
          <el-pagination
            v-show="total > 0"
            layout="prev, pager, next,jumper"
            v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize"
            :total="total"
            @current-change="handleCurrentChange"
          />
        </div>
      </el-card>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" size="small" @click="handleVisible()">关闭</el-button>
        </div>
      </template>
    </el-dialog>
  </template>
  <script name="ProfileResult" setup>
  import {
    formItemsForCap,
    formItemsForT,
    formItemsForI,
    formItemsForFI,
    formItemsForFz,
    formItemsForFZFF,
    formItemsForFZAFF,
    formItemsForFC,
    formItemsForFCSF,
    formItemsForFL,
    formItemsForFLATI,
    formItemsForFLA,
    formItemsForFG,
    formItemsForFGM,
    formItemsForFGI,
    formItemsForFGATIW,
    formItemsForFGTI,
    formItemsForFGA
  } from '../profileLibrary.js';
  
  const props = defineProps(['resultVisible', 'rowData']);
  const emit = defineEmits(['handleResultEvent']);
  const algorithms = ref([]);
  const basicData = ref(null);
  const tableData = ref(props.rowData?.resultList || []);
  const queryParams = ref({
    algorithm: '',
    pageNum: 1,
    pageSize: 10
  });
  const total = ref(0);
  
  if (props?.rowData) {
    switch (props?.rowData?.type) {
      case 'CAP': {
        basicData.value = formItemsForCap;
        break;
      }
      case 'T': {
        basicData.value = formItemsForT;
        break;
      }
      case 'I': {
        basicData.value = formItemsForI;
        break;
      }
      case 'FI': {
        basicData.value = formItemsForFI;
        break;
      }
      case 'FI': {
        basicData.value = formItemsForFI;
        break;
      }
      case 'FZ': {
        basicData.value = formItemsForFz;
        break;
      }
      case 'FZFF': {
        basicData.value = formItemsForFZFF;
        break;
      }
      case 'FZAFF': {
        basicData.value = formItemsForFZAFF;
        break;
      }
      case 'FC': {
        basicData.value = formItemsForFC;
        break;
      }
      case 'FCSF': {
        basicData.value = formItemsForFCSF;
        break;
      }
      case 'FL': {
        basicData.value = formItemsForFL;
        break;
      }
      case 'FLATI': {
        basicData.value = formItemsForFLATI;
        break;
      }
      case 'FLA': {
        basicData.value = formItemsForFLA;
        break;
      }
      case 'FGO': {
        basicData.value = formItemsForFG;
        break;
      }
      case 'FGM': {
        basicData.value = formItemsForFGM;
        break;
      }
      case 'FGI': {
        basicData.value = formItemsForFGI;
        break;
      }
      case 'FGATIW': {
        basicData.value = formItemsForFGATIW;
        break;
      }
      case 'FGTI': {
        basicData.value = formItemsForFGTI;
        break;
      }
      case 'FGA': {
        basicData.value = formItemsForFGA;
        break;
      }
    }
  }
  const basicKeys = Object.keys(basicData);
  const columns = ref([
    { label: 'E', prop: 'e' },
    { label: 'G', prop: 'g' },
    { label: 'Xc', prop: 'xc' },
    { label: 'A', prop: 'a' },
    { label: 'I1', prop: 'i1' ,width:120},
    { label: 'I2', prop: 'i2' ,width:120}
  ]);
  const handleVisible = () => {
    emit('handleResultEvent');
  };
  // 选择算法，执行结果查询
  const changeAlgorithm = (event) => {};
  // 翻页查询
  const handleCurrentChange = (num) => {
    queryParams.value.pageNum = num;
    doQuery();
  };
  // 执行查询
  const doQuery = () => {};
  onMounted(() => {
    doQuery();
  });
  </script>
  <style lang="scss" scoped>
  .result {
    margin-top: 10px;
  }
  .basic {
    .split{
      width: 100%;
      height: 1px;
      background: #909399;
      opacity: 0.5;
      margin: 5px 0;
    }
    .row {
      display: flex;
      margin-top: 10px;
      font-size: 12px;
      flex-wrap: wrap;
      .item {
        width: 33%;
        padding:4px;
        >span:nth-child(1){
          width: 120px;
          display: inline-block;
          text-align: right;
        }
        >span:nth-child(2){
          // width: 100px;
          display: inline-block;
          text-align: left;
          color:#909399;
        }
      }
    }
  }
  </style>